function run(max_time)


global_statement;
global current_time;
% Event driven simulation loop
while 1
    [min_instant, min_index] = min([EventList(:).instant]);
    if isempty(min_instant)
        break;
    end
    if min_instant > max_time
        break;
    end
    debug_event = EventList(min_index);
    if(strcmp(debug_event.etype,'send_phy'))
        a = 1;
    end
    current_time = min_instant;
    if current_time >=11.001
        1111;
    end
    NewEvents = action(EventList(min_index));      % Get new events from executing the latest 'action'
    EventList(min_index) = [];                     % Delete the latest event which has been just executed.
    EventList = [NewEvents; EventList];   % Append new events generated by executing the latest event
end

return;